//
//  MoreSettingsViewController.m
//  NiuBanJinGold
//
//  Created by Billy on 15/10/10.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "MoreSettingsViewController.h"
#import "SafeCentreViewController.h"
#import "HelpCentreViewController.h"
#import "WebViewController.h"
#import "SuggestUsViewController.h"
#import "InviteFirendsViewController.h"
#import "ContactUsViewController.h"
#import "RetrievingPWDViewController.h"
#import <ShareSDK/ShareSDK.h>
@interface MoreSettingsViewController ()<UITableViewDelegate , UITableViewDataSource , ISSShareViewDelegate >
@property (nonatomic , strong) NSArray *array_moreArr1;
@property (nonatomic , strong) NSArray *array_imageArr1;
@property (nonatomic , strong) NSArray *array_moreArr2;
@property (nonatomic , strong) NSArray *array_imageArr2;
@property (nonatomic , strong) NSArray *array_moreArr3;
@property (nonatomic , strong) NSArray *array_imageArr3;
@property (nonatomic , assign) BOOL activity;//活动中心是否存在
@property (nonatomic , strong) NSString *activity_title;
@property (nonatomic , strong) NSString *url;
@property (nonatomic , strong) NSString *logoUrl;
@end

@implementation MoreSettingsViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self getDataFormNet];
}
-(void)getDataFormNet {
    
    NSDictionary *dic_info = @{@"userId" : GETCURRENTUSERINOBYPRAMETERES(user_userId) , @"token" : GETCURRENTUSERINOBYPRAMETERES(user_userToken)};
    [[NETWorkingUtil sharedNETWorking] zzjrMore_moreInfoByParmeteres:dic_info  transferResultUsingBlock:^(id parsedData, NSError *error) {
        if (!error) {  //没有网络错误

            // 开始解析数据
            NSDictionary *dic = parsedData;
            
            if([dic[@"status"] intValue] == 0) {
                
                NSDictionary *dic_result = dic[@"result"];
                self.activity = [dic_result[@"activitySwitch"] boolValue];
                self.activity_title = dic_result[@"title"];
                self.url = dic_result[@"url"];
                self.logoUrl = dic_result[@"logoUrl"];
                if (self.activity == YES) {
                    
                    self.array_moreArr1 = @[@"安全保障" , @"帮助中心" , self.activity_title];
                    self.array_imageArr1 = @[@"more-aqzx.png" , @"more-bzzx.png", @"activity.png"];
                    NSLog(@"%@" , self.activity_title);
                    UITableView *tableView = (UITableView *)[self.view viewWithTag:444];
                    [tableView reloadData];
                }
                } else {// 不是网络出错, 其它错误
                
                [UsefulUtil showAlertView:dic[@"msg"]];
                
                    
            }
        }else {
            

//            [UsefulUtil showAlertView:@"遇到网络问题,请稍后重试!"];
            
        }
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"更多";
    
    self.navigationItem.leftBarButtonItem = nil;
    
    [self loadTableView];
    
}
-(void)loadTableView {
    
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT + MULTIPLYHEIGHT(50)) style:UITableViewStylePlain];
    tableView.tag = 444;
        [tableView setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
    tableView.backgroundColor = BASECOLOR;
    [tableView setSeparatorColor:[UsefulUtil colorWithHexString:@"#c8c7cc"]];
    
    UIView *view_footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, MULTIPLYHEIGHT(20))];
    
    [tableView setTableFooterView:view_footView];
    [view_footView setBackgroundColor:BASECOLOR];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
   
    
        
        self.array_moreArr1 = @[@"安全保障" , @"帮助中心" ];
        self.array_imageArr1 = @[@"more-aqzx.png" , @"more-bzzx.png"];

    
    self.array_moreArr2 = @[ @"牛板金介绍" , @"牛板金服务协议" , @"联系我们" , @"意见反馈" ];
    self.array_imageArr2 = @[@"more-nqbjs.png" , @"xieyi.png" ,  @"more-lxwm.png" , @"more-yjfk.png"];
    self.array_moreArr3 = @[@"邀请好友" , @"转发好友" ];
    self.array_imageArr3 = @[@"more-yqhy.png" , @"more-zfhy.png" ];
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, MULTIPLYHEIGHT(2.0 / 2))];

    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    CGFloat height = 0.0 ;
    if (section == 0) {
       height = MULTIPLYHEIGHT(30.0 / 2) ;
    }
    if (section == 1) {
        height = MULTIPLYHEIGHT(30.0 / 2);
        
    }
    if (section == 2) {
        height = MULTIPLYHEIGHT(30.0 / 2);
    }
    return height;
}

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UIView *view = [UsefulUtil viewCreationWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, MULTIPLYHEIGHT(2.0/2)) backgroundColor:BASECOLOR backGroundImage:nil];

    return view;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSInteger  number = 0;
    if (section == 0) {
        number = self.array_moreArr1.count;
        
    }
    if (section == 1) {
        number = self.array_moreArr2.count;
        
    }
    if (section == 2) {
        number = self.array_moreArr3.count;
    }
    return number;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
   
    static NSString *cellID = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (nil == cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
        
    }
    cell.textLabel.font = [UIFont systemFontOfSize:15.0];
    cell.textLabel.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (indexPath.section == 0) {
        
        cell.textLabel.text = [self.array_moreArr1 objectAtIndex:indexPath.row];
        cell.imageView.image = [UIImage imageNamed:[self.array_imageArr1  objectAtIndex:indexPath.row]];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头
}
    if (indexPath.section == 1) {
        cell.textLabel.text = [self.array_moreArr2 objectAtIndex:indexPath.row];
        cell.imageView.image = [UIImage imageNamed:[self.array_imageArr2 objectAtIndex:indexPath.row]];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    if (indexPath.section == 2) {
        cell.textLabel.text = [self.array_moreArr3 objectAtIndex:indexPath.row];
        cell.imageView.image = [UIImage imageNamed:[self.array_imageArr3 objectAtIndex:indexPath.row]];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        WebViewController *webVC = [[WebViewController alloc]init];
        webVC.index = 7;
        webVC.hidesBottomBarWhenPushed  = YES;
        [self.navigationController pushViewController:webVC animated:YES];
    }else {
        
    }
    if (indexPath.section == 0 && indexPath.row == 1) {
        HelpCentreViewController *helpVC = [[HelpCentreViewController alloc]init];
        [helpVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:helpVC animated:YES];
    }else {
        
    }
    if (indexPath.section == 0 && indexPath.row == 2) {
        WebViewController *webVC  = [[WebViewController alloc]init];
       webVC.index = 8;
        webVC.activity_url = self.url;
        [webVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:webVC animated:YES];

    }else {
        
    }
    if (indexPath.section == 1 && indexPath.row == 0  ) {
        WebViewController *webVC = [[WebViewController alloc]init];
        webVC.index = 4;
        [webVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:webVC animated:YES];
    }else {
        
    }
    if (indexPath.section == 1 && indexPath.row == 1  ) {
        WebViewController *webVC = [[WebViewController alloc]init];
        webVC.index = 10;
        [webVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:webVC animated:YES];
    }else {
        
    }
    if (indexPath.section == 1 && indexPath.row == 2  ) {
        WebViewController *webVC = [[WebViewController alloc]init];
        webVC.index = 5;
        [webVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:webVC animated:YES];
    }else {
        
    }
    if (indexPath.section == 1 && indexPath.row == 3) {
        SuggestUsViewController *suggestVC = [[SuggestUsViewController alloc]init];
        [suggestVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:suggestVC animated:YES];

    }else {
        
    }
    if (indexPath.section == 2 && indexPath.row == 0 ) {
        
        InviteFirendsViewController *InviteVC = [[InviteFirendsViewController alloc]init];
        [InviteVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:InviteVC animated:YES];
        
    }else {
        
    }
    if (indexPath.section == 2 && indexPath.row == 1) {
        NSLog(@"分享");
//        //1、构造分享内容
////        1.1、要分享的图片（以下分别是网络图片和本地图片的生成方式的示例）
////                id<ISSCAttachment> remoteAttachment = [ShareSDKCoreService attachmentWithUrl:@"http://style.niubangold.com/app/images/share/share.png"];
//        id<ISSCAttachment> localAttachment = [ShareSDKCoreService attachmentWithPath:[[NSBundle mainBundle] pathForResource:@"shre" ofType:@"png"]];
//        NSString *URL = [NSString stringWithFormat:@"http://m.niubangold.com/register.html?inviter=%@" , GETCURRENTUSERINOBYPRAMETERES(user_inviteCode)];
//        
////        1.2、以下参数分别对应：内容、默认内容、图片、标题、链接、描述、分享类型
//        id<ISSContent> publishContent = [ShareSDK content:@"8~12%年化收益率，是银行活期30倍+，安全，便捷，随存随取，快来注册吧~"
//                                           defaultContent:nil
//                                                    image:localAttachment
//                                                    title:@"一样的活期，不一样的收益"
//                                                      url:URL
//                                              description:@"8~12%年化收益率，是银行活期30倍+，安全，便捷，随存随取，快来注册吧~"
//                                                mediaType:SSPublishContentMediaTypeNews];
//        
//        //1+、创建弹出菜单容器（iPad应用必要，iPhone应用非必要）
//        id<ISSContainer> container = [ShareSDK container];
//        [container setIPadContainerWithView:self.view arrowDirect:UIPopoverArrowDirectionUp];
//        
////        2、展现分享菜单
//        [ShareSDK showShareActionSheet:container
//                             shareList:nil
//                               content:publishContent
//                         statusBarTips:NO
//                           authOptions:nil
//                          shareOptions:nil
//                                result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
//                                    
//                                    NSLog(@"=== response state :%zi ",state);
//                                    
//                                    //可以根据回调提示用户。
//                                    if (state == SSResponseStateSuccess)
//                                    {
//                                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"成功"
//                                                                                        message:nil
//                                                                                       delegate:self
//                                                                              cancelButtonTitle:@"OK"
//                                                                              otherButtonTitles:nil, nil];
//                                        [alert show];
//                                    }
//                                    else if (state == SSResponseStateFail)
//                                    {
//                                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failed"
//                                                                                        message:[NSString stringWithFormat:@"Error Description：%@",[error errorDescription]]
//                                                                                       delegate:self
//                                                                              cancelButtonTitle:@"OK"
//                                                                              otherButtonTitles:nil, nil];
//                                        [alert show];
//                                    }
//                                }];

        
        
        
    
        NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"shre" ofType:@"png"];
        NSString *URL = [NSString stringWithFormat:@"http://m.niubangold.com/register.html?inviter=%@",GETCURRENTUSERINOBYPRAMETERES(user_inviteCode)];
        //构造分享内容
        id<ISSContent> publishContent = [ShareSDK content:@"8~12%年化收益率，是银行活期30倍，安全，便捷，随存随取，快来注册吧~"
                                           defaultContent:@""
                                                    image:[ShareSDK imageWithPath:imagePath]
                                                    title:@"一样的活期，不一样的收益"
                                                      url:URL
                                         
                                              description:NSLocalizedString(@"8~12%年化收益率，是银行活期30倍，安全，便捷，随存随取，快来注册吧~", @"一样的活期，不一样的收益")
                                                mediaType:SSPublishContentMediaTypeNews];
        [publishContent addSinaWeiboUnitWithContent:[NSString stringWithFormat:@"%@%@",@"一样的活期，不一样的收益.8~12%年化收益率，是银行活期30倍，安全，便捷，随存随取，快来注册吧~",URL] image:[ShareSDK imageWithPath:imagePath]];
        
        //定制QQ空间信息
        [publishContent addQQSpaceUnitWithTitle:NSLocalizedString(@"一样的活期，不一样的收益", @"Hello QQ空间")
                                            url:INHERIT_VALUE
                                           site:nil
                                        fromUrl:nil
                                        comment:INHERIT_VALUE
                                        summary:INHERIT_VALUE
                                          image:INHERIT_VALUE
                                           type:INHERIT_VALUE
                                        playUrl:nil
                                           nswb:nil];
        //定制微信好友信息
        [publishContent addWeixinSessionUnitWithType:INHERIT_VALUE
                                             content:INHERIT_VALUE
                                               title:NSLocalizedString(@"一样的活期，不一样的收益", @"8~12%年化收益率，是银行活期30倍，安全，便捷，随存随取，快来注册吧~")
                                                 url:INHERIT_VALUE
                                          thumbImage:[ShareSDK imageWithPath:imagePath]
                                               image:INHERIT_VALUE
                                        musicFileUrl:nil
                                             extInfo:nil
                                            fileData:nil
                                        emoticonData:nil];
        //定制短信信息
        [publishContent addSMSUnitWithContent:[NSString stringWithFormat:@"%@%@",@"一样的活期，不一样的收益.8~12%年化收益率，是银行活期30倍，安全，便捷，随存随取，快来注册吧~",URL]];
    
        
        //弹出分享菜单
        [ShareSDK showShareActionSheet:nil
                             shareList:nil
                               content:publishContent
                         statusBarTips:YES
                           authOptions:nil
                          shareOptions:nil
                                result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                                    
                                    if (state == SSResponseStateSuccess)
                                    {
//                                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"成功"
//                                                                                        message:nil
//                                                                                       delegate:self
//                                                                              cancelButtonTitle:@"OK"
//                                                                              otherButtonTitles:nil, nil];
//                                        [alert show];
                                    }
                                    else if (state == SSResponseStateFail)
                                    {
                                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failed"
                                                                                        message:[NSString stringWithFormat:@"Error Description：%@",[error errorDescription]]
                                                                                       delegate:self
                                                                              cancelButtonTitle:@"OK"
                                                                              otherButtonTitles:nil, nil];
                                        [alert show];

                                              }
                                              }];
                                              }
    
    



}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
